#include <stdlib.h>
#include <core/errno.h>

int atoi(const char *str, int *pval)
{
	int val = 0;
	const char *iter;


	if ('-' == *str)
		iter = str + 1;
	else
		iter = str;

	while (*iter != '\0')
	{
		if (!ISDIGIT(*iter))
			return -EINVAL;

		val = val * 10 + *iter - '0';
		iter++;
	}

	if ('-' == *str)
		*pval = 0 - val;
	else
		*pval = val;

	return 0;
} 

